package module.main.view.mainInterface.playerresourcepanel
{
	
	import code.utils.MaterialUtil;
	
	import com.darwin.darwinUI.containers.ContainerBase;
	import com.darwin.darwinUI.controls.Label;
	import com.darwin.darwinUI.core.UIComponent;
	import com.darwin.darwinUI.general.TextFieldFactory;
	
	import flash.display.Sprite;
	import flash.text.TextField;
	
	import module.main.view.MainView;
	import module.main.view.ResourceConst;
	import module.main.view.mainInterface.PlayGradePlane;

	/**
	 *资源部件 
	 * @author jichang
	 * 
	 */
	public class ResourceInformationItem extends ContainerBase
	{
		private var _resourceInformationBackground:Sprite;
		private var _resourceNameStr:String;
		private var _resourceNumTxt:Label;
		private var _resourceIcon:Sprite;
		private var uicommand:UIComponent;
		public function ResourceInformationItem(ResourceName:String)
		{
			uicommand = new UIComponent();
			_resourceNameStr = ResourceName;
			_resourceInformationBackground = MaterialUtil.getPreloadMaterial("main",ResourceConst.RESOURCEINFO_BACKGROUND_PANEL) as Sprite;
			_resourceNumTxt = TextFieldFactory.getInstance().getLabel("mainInterface_resource_number");
//			_resourceNumTxt = Dll.getInstance().getDisplayObjectByName(ResourceConst.RESOURCEINFO_NUM) as Sprite;
//			if(_resourceNameStr == ResourceConst.RESOURCEINFO_FERRUM_ICON)
//			{
//				_resourceNumTxt.text = MainView.getInstance().playerObj.iron.toString();
//			}else if(_resourceNameStr == ResourceConst.RESOURCEINFO_STONG_ICON)
//			{
//				_resourceNumTxt.text = MainView.getInstance().playerObj.stone.toString();
//			}else if(_resourceNameStr == ResourceConst.RESOURCEINFO_WOOD_ICON)
//			{
//				_resourceNumTxt.text = MainView.getInstance().playerObj.wood.toString();
//			}else if(_resourceNameStr == ResourceConst.RESOURCEINFO_FOOD_ICON)
//			{
//				_resourceNumTxt.text = MainView.getInstance().playerObj.food.toString();
//			}else{
				_resourceNumTxt.text = "99999";
//			}
			_resourceIcon = MaterialUtil.getPreloadMaterial("main",_resourceNameStr) as Sprite;
			this.width = _resourceInformationBackground.width;
			this.height = _resourceInformationBackground.height;
			uicommand.width = _resourceInformationBackground.width;
			uicommand.height = _resourceInformationBackground.height;
			addItem(uicommand);
			init();
		}

		public function get resourceNumTxt():Label
		{
			return _resourceNumTxt;
		}

		public function set resourceNumTxt(value:Label):void
		{
			_resourceNumTxt = value;
		}

		private function init():void
		{
			putresourceInformationBackground();
			putresourceIcon();
			putresourceNum();
		}
		private function putresourceInformationBackground():void
		{
			_resourceInformationBackground.x = 0;
			_resourceInformationBackground.y = 0;
			uicommand.addChild(_resourceInformationBackground);
		}
		private function putresourceNum():void
		{
			_resourceNumTxt.x = 35;
			_resourceNumTxt.y = 10;
//			_resourceNumTxt.x = _resourceIcon.x + _resourceIcon.width +( this.width - _resourceIcon.x - _resourceIcon.width - _resourceNumTxt.width) / 2;
//			_resourceNumTxt.y = _resourceIcon.y +( this.height - _resourceIcon.y - _resourceIcon.height - _resourceNumTxt.height) / 2;
			uicommand.addChild(_resourceNumTxt);
		}
		private function putresourceIcon():void
		{
			_resourceIcon.x = 10;
			_resourceIcon.y = 10;
			uicommand.addChild(_resourceIcon);
		}
	}
}